<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
    />
    <meta name="author" content="林镭特" />
    <title></title>
   
    <style>
      main {
        background-color: #000;
        display: flex;
        flex-wrap: wrap;
        width: 180px;
        height: 80px;
        margin: 0 auto;
        text-align: center;
      }
      div {
        color: #fff;
      }
      .min,
      .sec {
        background-color: #fff;
        color: #000;
        width: 30px;
        height: 25px;
        margin-left: 25px;
      }
      button {
        width: 150px;
        height: 40px;
        margin-left: 15px;
        background-color: #0000ff;
        color: #fff;
      }
    </style>
  </head>
  <body>
    <!-- 倒计时 -->
    <main>
      <div class="min">01</div>
      <div class="text">分钟</div>
      <div class="sec">10</div>
      <div class="text">秒</div>
      <button>开始倒计时</button>
    </main>

    <script>
      var button = document.querySelector("button");
      var sec = document.querySelector(".sec");
      var min = document.querySelector(".min");
      sec.innerHTML;
      var time;
      button.onclick = function() {
        time = setInterval(fn, 1000);
        console.dir(setInterval);
      };

      function fn() {
        sec.innerHTML--;
        if (sec.innerHTML == 0&&min.innerHTML!=0) {
          min.innerHTML--;
          sec.innerHTML = "59";
        }
        else if(min.innerHTML == 0 && sec.innerHTML == 0) {
          return clearInterval(time);
        }
      }
    </script>
  
  </body>
</html>
